<template>
    <div>
        <el-card class="box-card" shadow="never">
            <!--导航栏-->
            <el-breadcrumb separator-class="el-icon-arrow-right">
                <el-breadcrumb-item>用户中心</el-breadcrumb-item>
                <el-breadcrumb-item>用户列表</el-breadcrumb-item>
            </el-breadcrumb>
            <!--分割线-->
            <div class="yx_line"></div>
            <el-row :gutter="10" style="margin-top:20px;">
               <el-col :span='6'>
                  <el-input v-model="nickname">
                    <template slot="prepend">昵称</template>
                  </el-input>
               </el-col>
            </el-row>
            <el-row class="yx_el_row">
                <el-col>
                    <el-button type="success" plain @click="search">筛选</el-button>
                </el-col>
            </el-row>
            <el-table class="yx_table" border :data="userlist">
                <el-table-column label="序号" width="100">
                     <template slot-scope="scope">{{(scope.$index+1)+(current_page-1)*20}}</template>
                </el-table-column>
                <el-table-column prop="avatar_url" label="头像" width="180">
                    <template slot-scope="scope">
                          <el-avatar :size="50" :src="scope.row.avatar_url"></el-avatar>
                    </template>
                </el-table-column>
                <el-table-column prop="nickname" label="昵称" width="200">
                </el-table-column>
                <el-table-column prop="gender" label="性别" width="100">
                </el-table-column>
                <el-table-column prop="is_member" label="身份" width="150">
                </el-table-column>
                <el-table-column prop="create_time" label="加入时间">
                </el-table-column>
            </el-table>
            <el-pagination class="yx_page"
                           background
                           @current-change="handle_current_change"
                           @size-change="handle_size_change"
                           :current-page="current_page"
                           :page-sizes="page_sizes"
                           :page-size="page_size"
                           layout="prev, pager, next,sizes, total"
                           :total="total_count">
            </el-pagination>
        </el-card>
    </div>
</template>

<script>
    export default {
        name: 'UserList',
        inject:['reload'],
        data() {
            return {
                current_page:1,
                page_size:20,
                showDialog:false,
                loading:false,
                nickname:'',
            }
        },
        methods: {
            getList(){
                var send_data={
                    api_token:this.$store.getters.getSessionId,
                    current_page:this.current_page,
                    page_size:this.page_size,
                    nickname:this.nickname,
                }
                this.$store.dispatch('loadUserList',send_data);
            },
            //跳转页
            handle_current_change(current_page){
                //当前页码数
                this.current_page=current_page;
                this.getList();
            },
            //修改条数
            handle_size_change(page_size){
                this.current_page=1;
                this.page_size=page_size;
                this.getList();
            },
            search(){
               this.current_page=1;
               this.getList();
            },
            edit(id,edit_type){
                this.$router.push({
                    name:'useredit',
                    params:{id:id,edit_type:edit_type}
                });
            },
        },
        created() {
            this.getList();
        },
        computed:{
            userlist(){
                return this.$store.getters.getUserList;
            },
            total_count(){
                return this.$store.getters.getUserTotalCount;
            },
            page_sizes(){
                return this.$store.state.page_sizes;
            },
        },
        watch:{
           userlist(val){
              if(val.length>0){
                for(let i in val){
                   val[i]['is_member']=val[i]['member_id']==null?'游客':'主播';
                }
              }
           }
        }
    }
</script>

<style>
     @import url('../../assets/css/table.css');
</style>
